
SynoLoader.strWindowFeatures = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";  

SynoLoader.onFirefoxLoad = function(event) {
  Components.utils.import("resource://SynoLoader/magnetHandler.js");
  document.getElementById("contentAreaContextMenu")
          .addEventListener("popupshowing", function (e){ SynoLoader.showFirefoxContextMenu(e); }, false);
  
  SynoLoader.httpResponseObserver = SynoLoader.SynoLoaderDMS.Util.createObserver();
  SynoLoader.httpResponseObserver.observe = function( aSubject, aTopic, aData ) 
  {	
	  if(aTopic == 'magnet-on-open-uri')
	  {
		  var aURI = aSubject.QueryInterface(Components.interfaces.nsIURI);
		  if(!aURI) return;
		  var uriText = aURI.spec;
		  SynoLoader.SynoLoaderDMS.syno_download_station.transfer_to_nas(uriText);
	  }
  };
  
  var observerService = Components.classes["@mozilla.org/observer-service;1"]
	.getService(Components.interfaces.nsIObserverService);

  observerService.addObserver( SynoLoader.httpResponseObserver, "magnet-on-open-uri", false);

};

SynoLoader.onMenuItemLinkCommand= function(event) {
	  alert(event);
    	if(SynoLoader.SynoLoaderDMS.DMS_Connect.connect==true)
	{
	    window.open(SynoLoader.SynoLoaderDMS.syno_download_station.url+"/webman/index.cgi?launchApp=SYNO.SDS.DownloadStation.Application", "Diskstation", SynoLoader.strWindowFeatures );  
	}
	else
	{
	SynoLoader.SynoLoaderDMS.Notification.show("No Connection");
	}

};

SynoLoader.onMenuItemCommand= function(event) {
    	if(SynoLoader.SynoLoaderDMS.DMS_Connect.connect==true)
	{
    	SynoLoader.SynoLoaderDMS.syno_download_station.transfer_to_nas(gContextMenu.linkURL);
	}
	else
	{
	SynoLoader.SynoLoaderDMS.Notification.show("No Connection");
	}

};


SynoLoader.onMenuItemDownloads = function(event) {

	 window.open("chrome://SynoLoader/content/SynoDownloads.xul", "SynoLoader Downloads", "chrome,centerscreen,width=500,height=600" );  
};

SynoLoader.showFirefoxContextMenu = function(event) {
  // show or hide the menuitem based on what the context menu is on
  document.getElementById("context-SynoLoader").hidden = (!gContextMenu.onLink);

};

SynoLoader.onCommand = function(event) {
  // show or hide the menuitem based on what the context menu is on
  alert(event);

};

window.addEventListener("load", function (e) { SynoLoader.onFirefoxLoad(); }, false);
window.addEventListener("load", function (e) { SynoLoader.onLoad(); }, false);
window.addEventListener("unload", function(e) { SynoLoader.shutdown(); }, false);
